package pl.th.permission;

import android.content.Intent;
import android.provider.Settings;

/**
 * request the permission {@link android.Manifest.permission#SYSTEM_ALERT_WINDOW}
 */
public class SAWindowPerMProcessor extends AbstractProcessor{

    public SAWindowPerMProcessor(String... permissions) {
        super(permissions);
    }

    @Override
    @SuppressWarnings({"ConstantConditions", "InlinedApi"})
    public void process(ProxyFragment proxy) {
        if (PermissionCompat.isAlertWindowPerGranted(proxy.getContext())) {
            proxy.workOnNextProcessor();
        } else {
            try {
                Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
                intent.setData(Utils.buildPackageUri(proxy.getContext()));
                proxy.startActivityForResult(intent);
            } catch (Exception e) {
                proxy.startActivityForResult(PermissionCompat.buildAppDetailIntent(proxy.getContext()));
            }
        }
    }
}
